import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/loginwait',
    component: () => import('@/views/login/loginwait'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/HomeView/index'),
      meta: { title: 'dashboard', icon: 'logoCircle' }
    }]
  },

  {
    path: '/HealthyCourse',
    alwaysShow: true,
    component: Layout,
    redirect: '/HealthyCourse/courselist',
    name: 'HealthyCourse',
    meta: { title: 'healthyCourse', icon: 'healthyCourse' },
    children: [
      {
        path: 'CourseList',
        name: 'CourseList',
        component: () => import('@/views/HealthyCourse/courselist'),
        meta: { title: 'courselist', icon: 'healthyCourse' }
      },
      {
        path: 'AddCourse',
        name: 'AddCourse',
        hidden: true,
        component: () => import('@/views/HealthyCourse/addcourse'),
        meta: { title: 'addcourse', icon: 'healthyCourse' }
      },
      {
        path: 'EditCourse/:course_id',
        name: 'EditCourse',
        hidden: true,
        component: () => import('@/views/HealthyCourse/editcourse'),
        meta: { title: 'editcourse', icon: 'healthyCourse' }
      },
      {
        path: 'DetailVideo/:course_id',
        name: 'DetailVideo',
        hidden: true,
        component: () => import('@/views/HealthyCourse/detailvideo'),
        meta: { title: 'detailvideo', icon: 'healthyCourse' }
      },
      {
        path: 'Adddetailvideo',
        name: 'Adddetailvideo',
        hidden: true,
        component: () => import('@/views/HealthyCourse/adddetailvideo'),
        meta: { title: 'adddetailvideo', icon: 'healthyCourse' }
      },
    ]
  },
  {
    path: '/HealthyArticle',
    alwaysShow: true,
    component: Layout,
    redirect: '/HealthyArticle/ArticleList',
    name: 'HealthyArticle',
    meta: { title: 'healthyArticle', icon: 'healthyArticle' },
    children: [
      {
        path: 'ArticleList',
        name: 'ArticleList',
        component: () => import('@/views/HealthyArticle/articlelist'),
        meta: { title: 'articlelist', icon: 'healthyArticle' }
      },
      {
        path: 'TopicList',
        name: 'TopicList',
        component: () => import('@/views/HealthyArticle/topiclist'),
        meta: { title: 'topiclist', icon: 'healthyArticle' }
      },
      {
        path: 'ExamList',
        name: 'ExamList',
        component: () => import('@/views/HealthyArticle/examlist'),
        meta: { title: 'examlist', icon: 'healthyArticle' }
      },
      {
        path: 'ExamInfo/:examId',
        name: 'ExamInfo',
        hidden: true,
        component: () => import('@/views/HealthyArticle/examinfo'),
        meta: { title: 'examinfo', icon: 'healthyArticle' }
      },
      {
        path: 'AddArticle',
        name: 'AddArticle',
        hidden: true,
        component: () => import('@/views/HealthyArticle/addarticle'),
        meta: { title: 'addarticle', icon: 'healthyArticle' }
      },
      {
        path: 'EditArticle/:articleId',
        name: 'EditArticle',
        hidden: true,
        component: () => import('@/views/HealthyArticle/editarticle'),
        meta: { title: 'editarticle', icon: 'healthyArticle' }
      },

    ]
  },


  {
    path: '/HealthyManger',
    alwaysShow: true,
    component: Layout,
    redirect: '/HealthyManger/usermachine',
    name: 'HealthyManger',
    meta: { title: 'healthyManage', icon: 'healthyManage' },
    children: [
      {
        path: 'UserMachine',
        name: 'UserMachine',
        component: () => import('@/views/HealthyManger/usermachine'),
        meta: { title: 'usermachine', icon: 'healthyManage' }
      },
      {
        path: 'MachineList',
        name: 'MachineList',
        hidden: true,
        component: () => import('@/views/HealthyManger/machinelist'),
        meta: { title: 'machinelist', icon: 'healthyManage' }
      }
    ]
  },
  {
    path: '/HealthyQA',
    alwaysShow: true,
    component: Layout,
    redirect: '/HealthyQA/qalist',
    name: 'HealthyQA',
    meta: { title: 'healthyQA', icon: 'healthyQA' },
    children: [
      {
        path: 'QAlist',
        name: 'QAlist',
        component: () => import('@/views/HealthyQA/qalist'),
        meta: { title: 'qalist', icon: 'healthyQA' }
      },

    ]
  },
  {
    path: '/HealthyMall',
    alwaysShow: true,
    component: Layout,
    redirect: '/HealthyMall/HealthyMall',
    name: 'HealthyMall',
    meta: { title: 'HealthyMall', icon: 'healthyMall' },
    children: [
      {
        path: 'Malllist',
        name: 'Malllist',
        component: () => import('@/views/HealthyMall/malllist'),
        meta: { title: 'malllist', icon: 'healthyMall' }
      },
      {
        path: 'AddMall',
        name: 'AddMall',
        hidden: true,
        component: () => import('@/views/HealthyMall/addmall'),
        meta: { title: 'addmall', icon: 'healthyMall' }
      },
      {
        path: 'EditMall/:goodsId',
        name: 'EditMall',
        hidden: true,
        component: () => import('@/views/HealthyMall/editmall'),
        meta: { title: 'editmall', icon: 'healthyMall' }
      }
    ]
  },
  {
    path: '/Ordermodule',
    alwaysShow: true,
    component: Layout,
    redirect: '/Ordermodule/orderlist',
    name: 'Ordermodule',
    meta: { title: 'order', icon: 'order' },
    children: [
      {
        path: 'Orderlist',
        name: 'Orderlist',
        component: () => import('@/views/Ordermodule/orderlist'),
        meta: { title: 'orderlist', icon: 'order' }
      },
    ]
  },
  {
    path: '/UserController',
    alwaysShow: true,
    component: Layout,
    redirect: '/UserController/userlist',
    name: 'UserController',
    meta: { title: 'userController', icon: 'healthyCourse' },
    children: [
      {
        path: 'UserList',
        name: 'UserList',
        component: () => import('@/views/UserController/userlist'),
        meta: { title: 'userlist', icon: 'healthyCourse' }
      },
      {
        path: 'AddUser',
        name: 'AddUser',
        hidden: true,
        component: () => import('@/views/UserController/adduser'),
        meta: { title: 'adduser', icon: 'healthyCourse' }
      },
      {
        path: 'EditUser/:user_id',
        name: 'EditUser',
        hidden: true,
        component: () => import('@/views/UserController/edituser'),
        meta: { title: 'edituser', icon: 'healthyCourse' }
      }
    ]
  },

  {
    path: '/CertificateManage',
    alwaysShow: true,
    component: Layout,
    redirect: '/CertificateManage/CertificateList',
    name: 'CertificateManage',
    meta: { title: 'CertificateManage', icon: 'healthyArticle' },
    children: [
      {
        path: 'CertificateList',
        name: 'CertificateList',
        component: () => import('@/views/CertificateManage/certificatelist'),
        meta: { title: 'certificatelist', icon: 'healthyArticle' }
      },
      {
        path: 'UserCertificate',
        name: 'UserCertificate',
        component: () => import('@/views/CertificateManage/usercertificate'),
        meta: { title: 'usercertificate', icon: 'healthyArticle' }
      },
      {
        path: 'CertificateData',
        name: 'CertificateData',
        hidden: true,
        component: () => import('@/views/CertificateManage/certificatedata'),
        meta: { title: 'certificatedata', icon: 'healthyArticle' }
      }
    ]
  },
  {
    path: '/ProblemFeedback',
    alwaysShow: true,
    component: Layout,
    redirect: '/ProblemFeedback/Feedbacklist',
    name: 'ProblemFeedback',
    meta: { title: 'ProblemFeedback', icon: 'feedbacklist' },
    children: [
      {
        path: 'Feedbacklist',
        name: 'Feedbacklist',
        component: () => import('@/views/ProblemFeedback/feedbacklist.vue'),
        meta: { title: 'feedbacklist', icon: 'feedbacklist' }
      },
    ]
  },
  {
    path: '/UserInfo',
    hidden: true,
    component: Layout,
    redirect: '/UserInfo/userinfo',
    name: 'UserInfo',
    meta: { title: 'UserInfo', icon: 'healthyArticle' },
    children: [
      {
        path: 'userinfo',
        name: 'userinfo',
        component: () => import('@/views/UserInfo/userinfo.vue'),
        meta: { title: 'UserInfo', icon: 'healthyArticle' }
      },
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}


//这里设置路由拦截
// router.beforeEach((to, from, next) => {

//   next();//http://localhost:8080/#/login?token=eyJKV1QiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NjYsImlhdCI6MTY2NTE0NzA4MiwianRpIjoiMTBkZjFmYzEyZjdhNGU2Mzk1YzNjODc0MDNlMzc0ZmMifQ.WDz1Y_LWmGCnN7JBvrFfrSRWr-StZbNLiEFxZ9Rn2Bg
//   if (to.path === '/login')  next({path:'/'});
//   //获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   //如果没有获取到token那么返回登录
//   if (!tokenStr) return next('/login')
//   //得到token就跳转页面，放行
//   next()

//   // next();

//   // let token = window.localStorage.getItem('token')
//   // console.log('zsjzsj',token);
//   // if (to.path === '/login?token=eyJKV1QiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NjYsImlhdCI6MTY2NTE0MzI1OSwianRpIjoiNGMxOWNlMGUwM2IxNDZiZjkyZTI5Mjc0NTAyZjkwZjQifQ.Le7qrqIkHRwy1s67TZ1aogBxKCYLi5pQfnGd05Ibr2E')
//   // next({
//   //               path:'/login/#/dashboard'
//   //             });
//   // var num = sessionStorage.getItem("token");
//   // console.log('123123',num);
//   // let token = this.$route.query.token;
//   // console.log('zsjzsj',token);
// })
//       var num = sessionStorage.getItem("token"); //这里是登录页面缓存的token
//       if (num == 'eyJKV1QiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NjYsImlhdCI6MTY2NTEzNTk4NCwianRpIjoiODQ5YzU0MzNiZDM3NDgyYWIyYzExYzRmOTZlZDE2MjIifQ.7tczQwD2_qxwGdF-9r-5PTMjxkDngHGSKMXI3vfB_eQ') { //判断token等于时候就跳转路由
//           next({
//             path:'/login/#/dashboard'
//           });//这个跳转是上面路由跳转
//       }
//       else { //token不一样时候就返回登录页面
//           next({
//               path: '/login',//返回登录界面
//               // query: {redirect: to.fullPath}
//           })
//       }

// }
// )



export default router
